package com.baichang.taoshunda.controller.mobile;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.controller.WebBaseController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.framework.model.Page;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.CityService;
import com.baichang.taoshunda.service.WaiterService;
import com.baichang.taoshunda.service.WaiterTypeService;
import com.baichang.taoshunda.service.WaiterlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

/**
 * Created by Administrator on 2018/1/30 0030.
 */
@Controller
@RequestMapping(ControllerConstants.WAITER)
public class WaiterServiceMCtroller extends BaseMobileController {

    @Autowired
    private WaiterlistService waiterlistService;
    @Autowired
    private WaiterTypeService waiterTypeService;
    @Autowired
    private CityService cityService;

    /**
     * 添加本地服务商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/addWaiterBusiness")
    public void addWaiterBusiness(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String waiterName = getString(json, "waiterName", "");
                Integer waiterType = getInt(json, "waiterType", 0);
                String waiterAddress = getString(json, "waiterAddress", "");
                Integer star = getInt(json, "star", 5);
                BigDecimal price = BigDecimal.valueOf(getDouble(json, "price", 0)); //本地服务商家的价钱
                //城市
                Integer cityId = getInt(json, "cityId", 0);
                //省级
                Integer provincesId = getInt(json, "provincesId", 0);
                //区域
                Integer regionId = getInt(json, "regionId", 0);
                String listPic = getString(json, "listPic", "");
                String picture = getString(json, "picture", "");
                String remark = getString(json, "remark", "");
                String lat = getString(json, "lat", "");
                String lng = getString(json, "lng", "");
                Integer userId = getInt(json, "userId", 0);
                String personalPic = getString(json, "personalPic", "");
                String businessPic = getString(json, "businessPic", "");
                Integer ifPayment = getInt(json, "ifPayment", 0); //是否收费
                BigDecimal money = BigDecimal.valueOf(getDouble(json, "money", 0));//年费
                String phone = getString(json, "phone", "");
                String name = getString(json, "phoneName", "");
                return waiterlistService.addWaiterBusiness(waiterName, waiterType, waiterAddress, star, price, listPic, picture, remark, cityId,
                        provincesId, regionId, lat, lng, userId, personalPic, businessPic, ifPayment, money, phone, name);
            }
        });
    }

    /**
     * 查询我的服务商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryWaiterBusinessList")
    public void queryWaiterBusinessList(final HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String businessName = getString(json, "businessName", "");
                Integer typeId = getInt(json, "typeId", 0);
                String address = getString(json, "address", "");
                Integer userId = getInt(json, "userId", 0);
                int nowPage = getInt(json, "nowPage", 1);
                int pageSize = getInt(json, "pageSize", 20);
                return waiterlistService.queryWaiterBusinessList(businessName, typeId, address, userId, nowPage, pageSize);
            }
        });
    }

    /**
     * 查询服务分类
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryWaiterType")
    public void queryWaiterType(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) throws ServiceException {
                return waiterTypeService.queryWaiterType();
            }
        });
    }

    /**
     * 获取城市
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getCityByParentId")
    public void getCityByParentId(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                int parentId = getInt(json, "parentId", 1);
                return cityService.getDeliveryCityByParentId(parentId);
            }
        });
    }

    /**
     * 查询商家详情
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryWaiterDetails")
    public void queryWaiterDetails(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer id = getInt(json, "id", 0);
                return waiterlistService.queryWaiterDetails(id);
            }
        });
    }

    /**
     * 删除服务商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/deleteWaiter")
    public void deleteWaiter(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer id = getInt(json, "id", 0);
                return waiterlistService.deleteWaiter(id);
            }
        });
    }

    /**
     * 修改服务商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/updateWaiterService")
    public void updateWaiterService(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer id = getInt(json, "id", 0);
                String waiterName = getString(json, "waiterName", "");
                Integer waiterType = getInt(json, "waiterType", 0);
                String waiterAddress = getString(json, "waiterAddress", "");
                BigDecimal price = BigDecimal.valueOf(getDouble(json, "price", 0)); //本地服务商家的价钱
                //城市
                Integer cityId = getInt(json, "cityId", 0);
                //省级
                Integer provincesId = getInt(json, "provincesId", 0);
                //区域
                Integer regionId = getInt(json, "regionId", 0);
                String listPic = getString(json, "listPic", "");
                String picture = getString(json, "picture", "");
                String remark = getString(json, "remark", "");
                String lat = getString(json, "lat", "");
                String lng = getString(json, "lng", "");
                Integer userId = getInt(json, "userId", 0);
                String personalPic = getString(json, "personalPic", "");
                String businessPic = getString(json, "businessPic", "");
                Integer ifPayment = getInt(json, "ifPayment", 0); //是够收费
                BigDecimal money = BigDecimal.valueOf(getDouble(json, "money", 0));//年费
                Integer payType = getInt(json, "payType", 0);
                String phone = getString(json, "phone", "");
                String name = getString(json, "phoneName", "");
                return waiterlistService.updateWaiterService(id, waiterName, waiterType, waiterAddress, price, cityId, provincesId, regionId, listPic,
                        picture, remark, lat, lng, userId, personalPic, businessPic, ifPayment, money, payType, phone, name);
            }
        });
    }

    /**
     * 服务商家支付
     *
     * @param request
     * @param response
     */
    @RequestMapping("/paymentMoney")
    public void payMentMoney(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer id = getInt(json, "id", 0);
                Integer userId = getInt(json, "userId", 0);
                Integer payType = getInt(json, "payType", 0);
                BigDecimal money = BigDecimal.valueOf(getDouble(json, "money", 0));
                return waiterlistService.payMentMoney(id, userId, payType, money);
            }
        });
    }

    /**
     * 缴费成功调用
     *
     * @param request
     * @param response
     */
    @RequestMapping("/updatePaymentMoney")
    public void updatePaymentMoney(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer id = getInt(json, "id", 0);
                Integer userId = getInt(json, "userId", 0);
                Integer payType = getInt(json, "payType", 0);
                BigDecimal money = BigDecimal.valueOf(getDouble(json, "money", 0));
                Integer ifPayment = getInt(json, "ifPayment", 1);
                return waiterlistService.updatePaymentMoney(id, userId, payType, money, ifPayment);
            }
        });
    }

    /**
     * 缴费失败调用
     *
     * @param request
     * @param response
     */
    @RequestMapping("/failPaymentMoney")
    public void failPaymentMoney(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer id = getInt(json, "id", 0);
                return waiterlistService.failPaymentMoney(id);
            }
        });
    }
}
